package services

import (
	"go-scripts/models"
	"gopkg.in/mgo.v2"
	"go-scripts/common"
)

type TmpInfoService struct {
	tmpInfoDao *mgo.Collection
	logger *common.Log
}

var tmpInfoService *TmpInfoService

func init()  {
}

func GetTmpInfoService() *TmpInfoService {
	if tmpInfoService != nil {
		return tmpInfoService
	}
	tmpInfoService = new(TmpInfoService)
	tmpInfoService.logger = common.GetLogger()
	var err error
	tmpInfoService.tmpInfoDao,err = models.GetModel().GetModelCollection("TmpInfo")
	if err != nil {
		tmpInfoService.logger.Fatal(err.Error())
	}
	return tmpInfoService
}
////获取最新的四大报数据，前100条
//func (t *TmpInfoService) GetNewTmpInfos() (map[bson.ObjectId]*News, error) {
//	redisService := GetRedisService()
//	var err error
//	//获取20小时之内的研报id
//	now := time.Now()
//	near20hourids := redisService.GetTmpInfoIdsByTime(now.Unix() - 20 * 3600, now.Unix())
//	//获取这些研报的次数
//	near20hourcounts := redisService.GetTmpInfoCountByIds(near20hourids)
//	//按照次数排序
//	sort.Sort(sort.Reverse(near20hourcounts))
//	//截取转载次数最多的前100条
//	if len(near20hourcounts) > 100 {
//		near20hourcounts = near20hourcounts[0:100]
//	}
//	//封装id为ObjectId
//	ids := common.ConverId2ObjectId(near20hourcounts, "Element")
//	//封装为新闻为map
//	newsMap := map[bson.ObjectId]*News{}
//	for _,v := range near20hourcounts {
//		report := new(News)
//		obj := bson.ObjectIdHex(v.Element)
//		report.id = obj
//		report.count = v.Score
//		newsMap[obj] = report
//	}
//	//获取dao
//	model := models.GetModel()
//	tmpInfoDao, err := model.GetModelCollection("TmpInfo")
//	if err != nil {return newsMap, err}
//	//初始化返回值
//	tmpInfos := []* models.TmpInfo{}
//}
//
//type News struct {
//	id bson.ObjectId
//	count float64
//	title string
//	stocks []string
//	themes []string
//}